<?php
/**
 * @author GhostWei
 * @date Oct 27, 2012
 */
abstract class oauth_api_request {
	
	const PUBLIC_TWEET_LIST = 'PUBLIC_WTEET_LIST';
	const USER_TWEET_LIST = 'USER_TWEET_LIST';
	const TOPIC_TWEET_LIST = 'TOPIC_TWEET_LIST';
	const TWEET_LINE = 'TWEET_LINE';
	const USER_LINE = 'USER_LINE';
	const HOT_TOPIC_LIST = 'HOT_TOPIC_LIST';
	
	protected $_config = null;
	protected $_oauth = null;
	protected $_name = 'twitter';
	protected $_params = array();
	protected $_url = array();
	protected $_flips = array();
	public function __construct(system_setting_oauth $config, community_oauth_row $oatuh) {
		$this->_config = $config;
		$this->_oauth = $oatuh;
		$this->init();
	}
	
	public function init(){}
	
	/**
	 * @return community_oauth_row
	 */
	public function getOauth() {
		return $this->_oauth;
	}
	
	/**
	 * @return system_setting_oauth
	 */
	public function getConfig() {
		return $this->_config;
	}
	
	public function getParams() {
		return $this->_params;
	}
	protected function flip_params(array $params) {
		foreach($params AS $key => $p) {
			if(in_array($key, array_keys($this->_flips))) {
				$this->_params[$this->_flips[$key]] = $p;
			} else {
				$this->_params[$key] = $p;
			}
		}
		return $this;
	}

	/**
	 * @return oauth_api_response
	 */
	public function fetch($action, array $params) {
		$this->flip_params($params);
		$class = 'oauth_open_' . $this->_name;
		$api = new $class();
		return $api->request((isset($this->_url[$action]) ? $this->_url[$action] : null), $this->_params);
	}
	
	
}
